<template>
  <div class="viewContain">
    <el-form :model="listQuery" size="small" label-width="100px">
      <el-row>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 6 }" :xl="{ span: 6 }">
          <el-form-item label="站点名称:">
            {{ orgName }}
          </el-form-item>
        </el-col>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 6 }" :xl="{ span: 6 }">
          <el-form-item label="采购单号:">
            {{ purchaseNum }}
          </el-form-item>
        </el-col>
        <el-col :xs="{ span: 24 }" :sm="{ span: 12 }" :md="{ span: 6 }" :xl="{ span: 6 }">
          <el-form-item label="备注:">
            {{ remarks }}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table
      ref="table"
      v-loading="loading"
      fit
      stripe
      :data="tableData"
      border
      size="mini"
    >
      <el-table-column align="center" label="序号" type="index" width="50">
        <template slot-scope="scope">
          <span>{{ (listQuery.pageNo - 1) * listQuery.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="productName" align="center" label="商品名称" />
      <el-table-column prop="productCode" align="center" label="商品编码" />
      <el-table-column prop="productNum" align="center" label="商品数量" />
    </el-table>
    <pagination
      :total-count="totalCount"
      :page.sync="listQuery.pageNo"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { perchaseRecord } from '@a/business/site.js'
import pagination from '@/components/pagination/index.vue'
export default {
  components: { pagination },
  data() {
    return {
      listQuery: {
        pageNo: 1,
        pageSize: 10,
        purchaseNum: ''
      },
      totalCount: 0, // 分页参数
      tableData: [],
      orgName: '',
      purchaseNum: '',
      remarks: '',
      loading: false
    }
  },
  mounted() {
    this.listQuery.purchaseNum = this.$route.params.id
    this.getList()
  },
  methods: {
    getList() {
      perchaseRecord(this.listQuery).then(res => {
        if (res.code === 0) {
          this.tableData = res.data.list
          this.orgName = this.tableData[0].orgName
          this.purchaseNum = this.tableData[0].purchaseNum
          this.remarks = this.tableData[0].remarks
          this.totalCount = res.data.total
          this.loading = false
        } else {
          this.loading = false
          this.$message({
            type: 'error',
            message: res.msg
          })
        }
      })
    }
  }
}
</script>
